<template>
	<view>
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item, i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.id">
					<!-- 动态绑定图片的src属性 -->
					<image :src="item.img"></image>
				</navigator>
			</swiper-item>
		</swiper>
		
		<!-- 分类导航区域 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,i) in navList" :key="i">
				<image :src="item.imgUrl" class="nav-img"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 轮播图
				swiperList: [],
				// 分类导航区
				navList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
		},
		methods: {
			// 获取轮播图
			async getSwiperList() {
				const { data: res } = await uni.$http.get("/api/getlunbo")
				console.log('res:', res)
				if(res.status !== 0) {
					// 请求失败
					console.error('请求失败')
					return uni.$showMsg('请求轮播图失败')
				} 
				this.swiperList = res.message
			},
			// 获取分类导航区
			async getNavList() {
				const { data: res } = await uni.$http.get("/api/catitems")
				console.log('res:', res)
				if(res.status !== 0) {
					// 请求失败
					console.error('请求失败')
					return uni.$showMsg('请求轮播图失败')
				} 
				this.navList = res.message
			}
		}
	}
</script>

<style lang="scss">
swiper {
	height: 330rpx;
	.swiper-item, image {
		width: 100%;
		height: 100%;
	}
}

.nav-list {
	display: flex;
	justify-content: space-around;
	margin: 15px 0;
	.nav-img {
		width: 128rpx;
		height: 140rpx;
	}
}
</style>
